package com.zth.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zth.pojo.Publics;
import com.zth.service.PublicService;

@RequestMapping("/publics")
@RestController
public class PublicController {
	@Autowired
	private PublicService publicService;
	
	@RequestMapping("/All")
	public List<Integer> All(){
		
		List<Publics> list= publicService.All();
		List<Integer> integers=new ArrayList<Integer>();
		integers.add(list.get(0).getA());
		integers.add(list.get(0).getB());
		integers.add(list.get(0).getC());
		integers.add(list.get(0).getD());
		integers.add(list.get(0).getE());
		return integers;
	}
	
	@RequestMapping("/typeSum")
	public List<Publics> typeSum(){
		//获取表中使用类型的数量
		List<Publics> list=publicService.typeSum();
		//储存获取到的id
		int[]is=new int[list.size()];
		//储存返回的值
		String[] index = new String[list.size()];
		
		//将获取到的id存入数组
		for(int i=0;i<list.size();i++) {
			is[i]=list.get(i).getCid();
		}
		
		//获取类型名称
		List<Publics> sPublics=publicService.CondById(is);
		List<Publics> list2=new ArrayList<Publics>();
		//储存要返回的值
		for(int i=0;i<list.size();i++) {
			//index[i]= "{name:"+sPublics.get(i).getCategory_name()+",value:"+list.get(i).getTypesum()+"}";
			Publics publics=new Publics();
			publics.setCategory_name(sPublics.get(i).getCategory_name());
			publics.setTypesum(list.get(i).getTypesum());
			list2.add(publics);
		}
		
		return list2;
	}
}
